package com.example.yls.demoa;

import android.content.Context;
import android.support.v7.widget.RecyclerView;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import java.util.List;

/**
 * Created by My Family on 2018/5/29.
 */

class CommentAdapter extends RecyclerView.Adapter<CommentAdapter.ViewHolder> {
    Context mContext;
    List<Comment> Comments;


    public CommentAdapter(Context context, List<Comment> Comments) {
    this.Comments = Comments;
    mContext = context;
    }

    @Override
    public ViewHolder onCreateViewHolder(ViewGroup parent, int viewType) {
        View view = LayoutInflater.from(mContext).inflate(R.layout.comment_list_item, parent,
                false);

        ViewHolder myViewHolder = new ViewHolder(view);
        return myViewHolder;
    }

    @Override
    public void onBindViewHolder(ViewHolder holder, int position) {
        holder.tvUserId.setText(Comments.get(position).getUser_id());
        holder.tvContent.setText(Comments.get(position).getContent());
    }


    @Override
    public int getItemCount() {
        if (Comments == null){
            return 0;
        }
        Log.e("getItemCount",""+Comments.size());
        return Comments.size();
    }

    public void changData(List<Comment> comments) {
        this.Comments = comments;
        notifyDataSetChanged();
    }

    public class ViewHolder extends RecyclerView.ViewHolder{
        TextView tvUserId;
        TextView tvContent;

        public ViewHolder(View itemView) {
            super(itemView);
            tvUserId = itemView.findViewById(R.id.tv_user_id);
            tvContent = itemView.findViewById(R.id.tv_comment_content);

        }
    }
}
